package com.taxi.controller;

import com.taxi.dto.DriverUser;
import com.taxi.dto.DriverUserWorkStatus;
import com.taxi.dto.TokenResult;
import com.taxi.result.Result;
import com.taxi.service.UserService;
import com.taxi.util.JwtUtils;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author: aniu
 * @Date: 2023/9/28
 * @ClassName: UserController
 * @Description: Write class functionality and purpose here.
 * @Version: 1.0
 */
@RestController
public class UserController {
    @Autowired
    private UserService userService;

    @ApiOperation("更新司机信息")
    @PutMapping("/update-user")
    public Result updateUser(@RequestBody DriverUser driverUser){
        return userService.updateUser(driverUser);
    }

    @GetMapping("/get-driver-info/{driverId}")
    public Result getDriverUserInfo(@PathVariable("driverId") Long driverId){
        return userService.getDriverUser(driverId);
    }
    @ApiOperation("修改司机工作状态")
    @PostMapping("/driver-user-work-status")
    public Result changeWorkStatus(@RequestBody DriverUserWorkStatus driverUserWorkStatus){
        return userService.changeWorkStatus(driverUserWorkStatus);
    }

    @ApiOperation("根据司机token查询司机和车绑定关系")
    @GetMapping("/driver-car-binding-relationship")
    public Result getDriverCarRelationShipByDriverPhone(HttpServletRequest request){
        String authorization = request.getHeader("Authorization");

        TokenResult tokenResult = JwtUtils.checkToken(authorization);
        String driverPhone = tokenResult.getPhone();
        return userService.getDriverCarRelationShipByDriverPhone(driverPhone);
    }

    @GetMapping("/work-status")
    public Result getWorkStatus(Long driverId){
        return userService.getWorkStatus(driverId);
    }
}
